<?php
namespace Erp\C\Orders\Tn\Api;
use Erp\C\Orders\Tn\Api\ApiShippingModule;
use Fn;
/**
 * 义达日本专线
*/
class ApiYdModule extends ApiShippingModule{
    public $header,$appToken,$url,$appKey;
    /**
     * ApiYdModule constructor.
     * 认证初始化
     */
    public function __construct(){
        $this->appToken = '5c17f41f1a65dec6772abef9bfb04298';
        $this->appKey	= '74fe11bef9044776921788afe6bccd6274fe11bef9044776921788afe6bccd62';
        $this->url		= "http://customer.ydhex.com/webservice/PublicService.asmx/ServiceInterfaceUTF8";
        $this->header	= array(
            "Content-Type:application/x-www-form-urlencoded;charset=utf-8"
        );
    }
    /**
     * @param $jsonData
     * @return array
     * 创建线上包裹
     */
    public function createAndConfirmPackages($jsonData){
        $logFileName = "ydApiGetMultiCurl".date("H",time());
        Fn\App::log($logFileName,$jsonData,"义达日本专线请求TN Curl数据开始");
        $multi_request_res = $this->multiCurl($jsonData);
        Fn\App::log($logFileName,$multi_request_res,"义达日本专线请求TN Curl数据结束");
        return $multi_request_res;
    }
    /**
     *查询订单的tn号
     *@param array $xmlData xml格式的数据,  string 订单号 字符串形式 '111221'
     */
    public function findTnCreatePackage($data){
        $orderid = $data;
        $paramsJson = json_encode(array('tracking_number'=>$orderid));
        $url = 'http://customer.ydhex.com/webservice/PublicService.asmx/ServiceInterfaceUTF8?paramsJson='.$paramsJson.'&appToken='.$this->appToken.'&appKey='.$this->appKey.'&serviceMethod=gettrack';
        $headers = $this->header;
        $logFileName = 'kim_ooo';
        if($logFileName){
            Fn\App::log($logFileName,$data,"义达 findTN Curl数据开始");
        }
        $res = $this->oneHttpRequest($url,'','GET',$headers);
        if($logFileName){
            Fn\App::log($logFileName,$res,"义达 findTN Curl数据结束");
        }
        $response[$orderid] = $res;
        return $response;
    }

    /**
     * @param $data
     * @return mixed
     * api请求获取包裹标签pdf
     */
    public function createPackageLable($data){
        $url = $this->url;
        $response = $this->oneHttpRequest($url,$data,'POST','');
        return $response;
    }
}